package com.fuluwa.domain.usercenter.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang3.StringUtils;

import com.fuluwa.domain.file.model.FileInfo;
import com.fuluwa.domain.security.model.User;
import com.fuluwa.domain.shared.AbstractDomainObject;
import com.fuluwa.domain.shared.AbstractIdDomainObject;
import com.fuluwa.infra.exception.PersistenceException;

@Entity
@Table(name = "uc_user_profile")
public class UserProfile extends AbstractDomainObject {
	public static enum GenderType {
		M, F, NONE;
	}
	//FIXME add account info into user profile?
	@Id
	private String userNo;
	
	@OneToOne
	@JoinColumn(name="user_id")
	private User user;
	

	private UserBasicInfo userBasicInfo;
	
	private SecurityInfo securityInfo;//define info how to find password back
	
	//registor change,maybe from weibo
	private String channelId;
	private String channelType;
	
	private CurrentStatus currentStatus;
	
	private Contact contact;
	
	private Education education;
	
	//emplyers,job posting
	//language
	
//	private Integer level=0;
//	@ManyToOne
//	@JoinColumn(name="user_class_id")
//	private UserClass userClass;//default is normal , maybe VIP
	
//	private Integer expValue=0;
	
	//

	
	@Temporal(TemporalType.TIMESTAMP)
	private Date registerTime = new Date();
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastUpdateTime = new Date();
	
	/*@ManyToMany
	@JoinTable(name = "uc_user_ude", joinColumns = { @JoinColumn(name = "user_profile_id") }, inverseJoinColumns = { @JoinColumn(name = "ude_id") })
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("id ASC")
	private List<UserDefineElement> udes = Lists.newArrayList();*/

	// TODO Add more user attributes
	private UserProfile() {
		// hibernate need it.
	}

	@Override
	protected Serializable getDomainId() {
		return userNo;
	}
	

	public UserProfile(User user, UserClass userClass) {
		this.user = user;
//		this.userClass = userClass;
		this.userNo="U"+StringUtils.leftPad(user.getId()+"", 10, "0");
	}

	public void updateUserBasicInfo(UserBasicInfo userBasicInfo) throws PersistenceException {
		this.userBasicInfo = userBasicInfo;
		this.update();
	}

	public void updateSecurityInfo(SecurityInfo securityInfo) throws PersistenceException {
		this.securityInfo = securityInfo;
		this.update();
	}

	public void updateCurrentStatus(CurrentStatus currentStatus) throws PersistenceException {
		this.currentStatus = currentStatus;
		this.update();
	}

	public void updateContact(Contact contact) throws PersistenceException {
		this.contact = contact;
		this.update();
	}

	public void updateEducation(Education education) throws PersistenceException {
		this.education = education;
		this.update();
	}

	public String getUserNo() {
		return userNo;
	}

	public User getUser() {
		return user;
	}

	public UserBasicInfo getUserBasicInfo() {
		return userBasicInfo;
	}

	public SecurityInfo getSecurityInfo() {
		return securityInfo;
	}

	public String getChannelId() {
		return channelId;
	}

	public String getChannelType() {
		return channelType;
	}

	public CurrentStatus getCurrentStatus() {
		return currentStatus;
	}

	public Contact getContact() {
		return contact;
	}

	public Education getEducation() {
		return education;
	}

//	public UserClass getUserClass() {
//		return userClass;
//	}

	public Date getRegisterTime() {
		return registerTime;
	}

	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	
	


}
